package com.netflexitysolutions.amazonws.ec2;

import java.util.HashMap;
import java.util.Map;

public enum InstanceState {

	PENDING(0, "pending"), RUNNING(16, "running"), SHUTTING_DOWN(32, "shutting-down"), TERMINATED(48, "terminated");
	
	private static Map<String, InstanceState> stateByName = new HashMap<String, InstanceState>();
	private static Map<Integer, InstanceState> stateByCode = new HashMap<Integer, InstanceState>();
	
	static {
		InstanceState[] states = InstanceState.values();
		for (InstanceState state : states) {
			stateByName.put(state.getName(), state);
			stateByCode.put(state.getCode(), state);
		}
	}
	
	public static InstanceState instanceStateForName(String name) {
		return stateByName.get(name);
	}
	
	public static InstanceState instanceStateForCode(int code) {
		return stateByCode.get(code);
	}
	
	private int code;
	
	private String name;
	
	/**
	 * @param code
	 * @param name
	 */
	private InstanceState(int code, String name) {
		this.code = code;
		this.name = name;
	}

	/**
	 * @return the code
	 */
	public int getCode() {
		return code;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}
	
}
